﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using InsuranceAdjuster.Services;
using InsuranceAdjuster.Web.Models;

namespace InsuranceAdjuster.OccasionallyConnected.Messages {
    public class GetReferenceDataMessage : Message {
        public GetReferenceDataMessage() {
            this.CacheRules = MessageDataSource.ServerOnly;
        }

        private void GetReferenceStates() {
            // Get States
            MarkAsyncStarted();
            GetDataService().GetStates(states =>
            {
                for (int x = 0; x < states.Count; x++)
                    ResponseEntities.Add("State" + x, new MessageResult(Verb.Read, Origin.Server, states[x]));

                MarkAsyncFinished();
            });
        }
        private void GetReferenceAppointments() {
            // Get Appointments            
            MarkAsyncStarted();
            ServiceProviderBase.Instance.InsuranceAdjusterDataService.GetAppointments(appointments =>
            {
                for (int x = 0; x < appointments.Count; x++)
                    this.ResponseEntities.Add("Result" + x, new MessageResult(Verb.Read, Origin.Server, appointments[x]));

                MarkAsyncFinished();
            });
        }

        protected override void OnlineOperation() {
            GetReferenceStates();
            GetReferenceAppointments();
        }
        protected override List<MessageResult> CompileServerResults() {
            return this.ResponseEntities.Select(x => x.Value).ToList();
        }
    }
}
